import { Controller, Post, Get, Req, Res } from "routing-controllers";
import { ACCOUNT_INTERFACE, accountInterface } from "service/account/account";
import { Inject, Service } from "typedi";
import { SitesList, SitesOptions } from "client/sitesVo";
import { VALID_TOKEN } from "config/const";

@Controller()
@Service()
export class ListController {
  @Inject(ACCOUNT_INTERFACE) private readonly account: accountInterface;

  // 店铺列表参数不动
  @Post("/sites/list")
  async list(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesList[] | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.getList({ request, response, userInfo });
  }

  // 没有参数
  @Post("/sites/options")
  async options(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.getOptions({ request, response, userInfo });
  }

  // 不动
  @Post("/sites/create_info")
  async create_info(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.get_create_info({ request, response, userInfo });
  }

  // 不动
  @Post("/sites/create")
  async create(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.create({ request, response, userInfo });
  }

  // 不动
  @Post("/sites/update")
  async update(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.update({ request, response, userInfo });
  }

  // 不动
  @Post("/sites/delete")
  async delete(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.delete({ request, response, userInfo });
  }

  // { platform: string}
  @Post("/sites/gethelp")
  async gethelp(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.getHelp({ request, response, userInfo });
  }

  // 获取店铺后台域名列表
  @Get("/sites/get_host")
  async get_host(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.getHost({ request, response, userInfo });
  }

  // 批量更新专利校验设置
  @Post("/sites/update_verify")
  async updateVerify(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.updateVerify({ request, response, userInfo });
  }

  // 批量变更店铺店铺归属
  @Post("/sites/update_orign")
  async updateOrign(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.updateOrign({ request, response, userInfo });
  }

  // 批量设置店铺状态
  @Post("/sites/update_status")
  async updateStatus(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.updateStatus({ request, response, userInfo });
  }

  // 获取自建站域名下拉
  @Post("/sites/get_zjz_options")
  async getZjzOptions(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesOptions | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.account.getZjzOptions({ request, response, userInfo });
  }
}
